<template>
  <el-dialog :visible="modelValue" @update:visible="val => $emit('update:modelValue', val)" title="角色信息">
    <el-form :model="role" ref="roleForm">
      <el-form-item label="角色名称" prop="name"
                    :rules="[{ required: true, message: '请输入角色名称', trigger: 'blur' }]">
        <el-input v-model="role.name"/>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="close">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </template>
  </el-dialog>
</template>

<script setup>
import {ref, watch} from 'vue';
import {defineProps, defineEmits} from 'vue';

const props = defineProps(['modelValue', 'currentRole']);
const emit = defineEmits(['update:modelValue', 'submit']);
const role = ref({name: ''});

watch(() => props.currentRole, (newRole) => {
  role.value = {...newRole};
});

const close = () => {
  emit('update:modelValue', false);
};

const submit = () => {
  emit('submit', role.value);
  close();
};
</script>

<style scoped>
</style>